#include <tenacitas.log/change_file_handler.h>

using namespace tenacitas::log;


// -----------------------------------------------------------------------------
std::string change_file_handler::m_dir_log( "./" );
std::string change_file_handler::m_pgm_name ( "NO-PGM" );
int64_t change_file_handler::m_pid ( -1 );




// -----------------------------------------------------------------------------
const std::string & 
change_file_handler::
file_name( int32_t p_file_index ) {
    std::stringstream l_stream;

    l_stream << m_dir_log << "/" << m_pgm_name << "_" << m_pid << "_";

    if ( m_thread_id == boost::thread::id( ) ) {
        l_stream << "0";
    }
    else {

        int64_t l_thread_id = tenacitas::boost_tools::th2int( m_thread_id );

        l_stream << std::dec << l_thread_id;
    }

    l_stream << "_" << std::setfill( '0' ) << std::setw( 10 ) << p_file_index;

    l_stream << ".log";

    m_current_file_name = l_stream.str( );

    return m_current_file_name;
}



